package com.chexiehui.jc.ui.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;

import com.aries.ui.view.radius.RadiusTextView;
import com.blankj.utilcode.util.RegexUtils;
import com.blankj.utilcode.util.StringUtils;
import com.chexiehui.jc.R;
import com.chexiehui.jc.base.BaseFragment;
import com.chexiehui.jc.entity.UserInfo;
import com.chexiehui.jc.utils.SerializableSpTools;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

public class ChangePhoneVerificationFragment extends BaseFragment {

    @BindView(R.id.et_old_phone)
    EditText etOldPhone;

    public static ChangePhoneVerificationFragment getInstance() {
        ChangePhoneVerificationFragment fragment = new ChangePhoneVerificationFragment();
        return fragment;
    }

    @BindView(R.id.rtv_next)
    RadiusTextView rtvNext;

    private UserInfo userInfo;
    private PageNextListener pageNextListener;

    @Override
    protected void beforeSetView() {
        userInfo = SerializableSpTools.getUserInfo();
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_change_phone_verification;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
    }

    private String getOldPhone(){
        return etOldPhone.getText().toString().trim();
    }

    @OnClick(R.id.rtv_next)
    public void onViewClicked() {
        if(StringUtils.isTrimEmpty(etOldPhone.getText().toString().trim())){
            showToast("请输入旧手机号");
            return;
        }
        if(!RegexUtils.isMobileSimple(getOldPhone())){
            showToast("请输入正确的手机号");
            return;
        }
        if(!getOldPhone().equals(userInfo.getTel())){
            showToast("与旧手机号不匹配");
            return;
        }
        if (pageNextListener != null) {
            pageNextListener.onChangePhoneVerificationNext();
        }
    }

    public interface PageNextListener {
        void onChangePhoneVerificationNext();
    }

    public void setPageNextListener(PageNextListener pageNextListener) {
        this.pageNextListener = pageNextListener;
    }
}
